import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import React, { useState, useRef, forwardRef, useImperativeHandle, useCallback, } from "react";
import { DevPopup } from "~/public/cpas-ui";
import { TextBox, TreeList } from "devextreme-react";
import AntTabs, { HocVerticalLeftStyleTab, } from "~/public/cpas-ui/components-ui/ant-components/AntTab";
import { Addsubject, AssistgetType, AutoAddChildrenForFZZ, autoAddFirstChildren, Editsubject, getNewKMBH, getSubjectSDB, getSubjectType, IsCanAddFZZ, SubjectDel, SubjectIsHasFZZ, } from "./DraftApi";
import { DevToolBar } from "~/public/cpas-ui";
import { Item } from "devextreme-react/toolbar";
import { Column } from "devextreme-react/tree-list";
import "./_style.less";
import notify from "devextreme/ui/notify";
import { CpasIcon } from "~/public/cpas-ui";
import { moneyFormat } from "../../../../CarryEntryPopup/components";
/**
 * ## 基于本地数据库，获取数据本地数据进行功能演示。
 * ~~~js
 * import SubjectPopup  from 'sright-ui'
 * ~~~
 */
export const AddPopup = forwardRef((props, ref) => {
    const [visible, setVisible] = useState(false);
    const [tabsData, setTabsData] = useState([]);
    const [SubjectSDBData, setSubjectSDBData] = useState([]);
    const [SubjectSDBDatas, setSubjectSDBDatas] = useState([]);
    const [selectMode, setSelectMode] = useState("");
    const [assistType, setAssistType] = useState("");
    const [TbsStates, setTbsStates] = useState("0");
    const [AddFZZMessage, setAddFZZMessage] = useState("");
    const [value, setValue] = useState("");
    const diaParams = useRef();
    const diaParamsData = useRef();
    const TreeListRef = useRef();
    const InputRef = useRef();
    const AuxiliaryRef = useRef();
    const AuxiliaryRefs = useRef();
    const ParentLevel = useRef();
    const curNodeRef = useRef();
    // 删除科目
    const DeleteSubjectRef = useRef();
    // 增加科目
    const SubjectPopupRef = useRef();
    // 编辑科目
    const EditSubjectsReft = useRef();
    // 自定义方法
    useImperativeHandle(ref, () => ({
        show: async (params) => {
            diaParams.current = params;
            setVisible(true);
            setSelectMode(diaParams.current?.selectMode);
            getSubjectSDBDatas();
            getSubjectTypeData();
        },
    }));
    // useEffect(() => {
    //   if (diaParams.current?.dbname) {
    //     getSubjectSDBDatas();
    //     getSubjectTypeData();
    //   }
    // }, [
    //   diaParams.current?.dbname,
    //   diaParams.current?.Data_ID,
    //   diaParams.current?.isHasFZZ,
    // ]);
    // 获取切换数据
    const getSubjectTypeData = async () => {
        const res = await getSubjectType({
            dbname: diaParams.current?.dbname,
            Data_ID: diaParams.current?.Data_ID,
        });
        if (res) {
            res.unshift({ code: "0", type: "全部" });
            setTabsData(res);
        }
        return [];
    };
    // 获取表格数据
    const getSubjectSDBDatas = async () => {
        const res = await getSubjectSDB({
            dbname: diaParams.current?.dbname,
            Data_ID: diaParams.current?.Data_ID,
            isHasFZZ: diaParams.current?.isHasFZZ,
        });
        setSubjectSDBData(res);
        setSubjectSDBDatas(res);
    };
    function handleStr(str) {
        var arr = str.replace(/[`:_.~!@#$%^&*() \+ =<>?"{}|, \/ ;' \\ [ \] ·~！@#￥%……&*（）—— \+ ={}|《》？：“”【】、；‘’，。、]/g, "");
        return arr;
    }
    // 模糊搜索
    const inputSearch = (content) => {
        TreeListRef.current.instance.searchByText(content || "");
    };
    // const throttleSearch = throttle(inputSearch, 100);
    const getInputValue = (e) => {
        const { event } = e;
        inputSearch(event.target.value);
        setValue(event.target.value);
    };
    // 标签页过滤表格数据
    const getSubjectListData = async (r) => {
        if (r === "全部") {
            if (SubjectSDBData.length > 0)
                setSubjectSDBDatas(SubjectSDBData);
        }
        else {
            if (SubjectSDBData.length > 0) {
                const KMLXData = SubjectSDBData.filter((item) => {
                    return item.KMLX && item.KMLX.includes(r);
                });
                setSubjectSDBDatas(KMLXData);
            }
            return [];
        }
    };
    const AccountTabsClick = useCallback(async (r) => {
        setTbsStates(r);
        if (tabsData) {
            tabsData.map(async (item) => {
                if (r === item.code) {
                    getSubjectListData(item.type);
                }
                return "";
            });
        }
    }, [tabsData, SubjectSDBData]);
    const onCellClick = (r) => {
        // let e = r.data.KMMC.match(/(\S*)-/);
        // let v = handleStr(r.data.PID);
        // if (e !== null) {
        //   ParentLevel.current = v + "-" + e[1];
        // }
        if (selectMode === "0") {
            diaParamsData.current = r.data;
        }
        else {
            const v = TreeListRef.current.instance.getSelectedRowsData("all");
            diaParamsData.current = v;
        }
    };
    // 判断是否可以增加辅助账
    async function IsCanAddFZZStates(v, KMBH) {
        if (v[0].code === 1) {
            setVisible(false);
            const r = await AssistgetType({
                dbname: diaParams.current?.dbname,
                Data_ID: diaParams.current?.Data_ID,
                KMBH: KMBH,
            });
            // 后期会在调一个 自动生成挂辅助账的科目名称 传给第一个参数
            diaParams.current?.okCallback(diaParamsData.current, r);
        }
        return {};
    }
    function IsMessage(r) {
        if (r) {
            notify(`${r}`, "warning", 2000);
        }
        else {
            notify("该科目不可增加辅助账", "warning", 2000);
        }
    }
    // 双击事件
    const onCellDblClick = async (r) => {
        const getdata = TreeListRef.current.instance?.getSelectedRowsData();
        console.log(getdata, "r------");
        //判断 是否为增加辅助账 tre 还是 增加科目 false
        if (diaParams.current?.auxiliaryState) {
            // 辅助账
            const IsHasFZZ = await SubjectIsHasFZZ({
                dbname: diaParams.current?.dbname,
                Data_ID: diaParams.current?.Data_ID,
                KMBH: r.data.KMBH,
            });
            // 判断 是否存在辅助账
            if (IsHasFZZ[0].isExists) {
                // console.log("存在");
                const IsCanAddFZZState = await IsCanAddFZZ({
                    dbname: diaParams.current?.dbname,
                    Data_ID: diaParams.current?.Data_ID,
                    KMBH: r.data.KMBH,
                });
                // 存在辅助账 判断是否可以增加辅助账
                IsCanAddFZZStates(IsCanAddFZZState, r.data.KMBH);
            }
            else {
                // console.log("不存在");
                const IsCanAddFZZState = await IsCanAddFZZ({
                    dbname: diaParams.current?.dbname,
                    Data_ID: diaParams.current?.Data_ID,
                    KMBH: r.data.KMBH,
                });
                if (IsCanAddFZZState[0].code === 0) {
                    setVisible(false);
                    IsMessage(IsCanAddFZZState[0].message);
                }
                else if (IsCanAddFZZState[0].code === 2) {
                    setVisible(false);
                    setAddFZZMessage(IsCanAddFZZState[0].message);
                    AuxiliaryRef.current.show({
                        title: "提示",
                        okCallback: async () => {
                            const value = await AutoAddChildrenForFZZ({
                                dbname: diaParams.current?.dbname,
                                Data_ID: diaParams.current?.Data_ID,
                                KMBH: r.data.KMBH,
                                editUser: diaParams.current?.editUser,
                            });
                            const v = await AssistgetType({
                                dbname: diaParams.current?.dbname,
                                Data_ID: diaParams.current?.Data_ID,
                                KMBH: value[0].KMBH,
                            });
                            diaParams.current?.okCallback(value, v);
                        },
                    });
                }
            }
            return [];
        }
        else {
            // 科目 判断 是否为末级
            if (diaParamsData.current?.isEnd) {
                setVisible(false);
                InputRef.current.show({
                    title: "提示",
                    okCallback: async () => {
                        GetautoAddFirstChildren(r.data);
                    },
                });
            }
            else {
                // 如果不是末级 直接返回参数 和关闭弹出框
                setVisible(false);
                const r = await getNewKMBH({
                    dbname: diaParams.current?.dbname,
                    Data_ID: diaParams.current?.Data_ID,
                    KMBH: diaParamsData.current.KMBH,
                });
                diaParams.current?.okCallback(diaParamsData.current, r.data);
            }
        }
    };
    const GetautoAddFirstChildren = async (data) => {
        console.log(data, "-----");
        if (diaParamsData.current.PID === "0") {
            const v = await autoAddFirstChildren({
                dbname: diaParams.current?.dbname,
                Data_ID: diaParams.current?.Data_ID,
                KMBH: diaParamsData.current.KMBH,
                editUser: diaParams.current?.editUser,
            });
            const r = await getNewKMBH({
                dbname: diaParams.current?.dbname,
                Data_ID: diaParams.current?.Data_ID,
                KMBH: diaParamsData.current.KMBH,
            });
            if (r)
                diaParams.current?.okCallback(data, r.data);
        }
        else {
            const v = await autoAddFirstChildren({
                dbname: diaParams.current?.dbname,
                Data_ID: diaParams.current?.Data_ID,
                KMBH: data.KMBH,
                editUser: diaParams.current?.editUser,
            });
            const r = await getNewKMBH({
                dbname: diaParams.current?.dbname,
                Data_ID: diaParams.current?.Data_ID,
                KMBH: data.KMBH,
            });
            if (r)
                diaParams.current?.okCallback(data, r.data);
        }
    };
    const relationMenuItems = function (e) {
        if (e.target == "content" && e.row?.rowType == "data") {
            const data = e.row?.data;
            const MatchKMMC = data.KMMC.match(/(\S*)-/);
            const indexss = data.KMMC.lastIndexOf("-");
            const resolvess = data.KMMC.substring(0, indexss);
            const ItemDataPid = handleStr(data.PID);
            ParentLevel.current = ItemDataPid + "-" + resolvess;
            curNodeRef.current = data;
            e.items = [
                {
                    text: "增加科目",
                    onItemClick: async (e) => {
                        const res = await getSubjectType({
                            dbname: diaParams.current?.dbname,
                            Data_ID: diaParams.current?.Data_ID,
                        });
                        // auxiliaryState 判断是否为辅助账 true 为辅助账 false 为科目
                        // 判断 科目是否为一级
                        if (curNodeRef.current.JC === 1) {
                            SubjectPopupRef.current.show({
                                args: {
                                    title: "新增科目",
                                    data: res,
                                    ParentLevel: "",
                                    PKMBH: data.KMBH,
                                },
                                okCallback: async (r) => {
                                    console.log(r, "------r");
                                    if (r) {
                                        if (r.superiorProject) {
                                            const itemNames = r.selectedYears
                                                ? r.selectedYears.map((item) => {
                                                    return item.itemName;
                                                })
                                                : "";
                                            const res = await Addsubject({
                                                dbname: diaParams.current?.dbname,
                                                Data_ID: diaParams.current?.Data_ID,
                                                KMBH: r.KMBH,
                                                KMMC: r.KMMC + "-" + r.SubjectNumber,
                                                editUser: diaParams.current?.editUser,
                                                PKMBH: r.PKMBH,
                                                YSKMBH: r.KMBHAdd.toString(),
                                                YSKMMC: r.SubjectNumber,
                                                KMFX: r.SelectName,
                                                KMLX: r.SelectType,
                                                JC: r.Satatejc + 1,
                                                itemNames: itemNames ? itemNames.join() : "",
                                            });
                                            if (res.ok) {
                                                notify("增加科目成功", "success", 2000);
                                                getSubjectSDBDatas();
                                            }
                                        }
                                        else {
                                            const itemNames = r.selectedYears
                                                ? r.selectedYears.map((item) => {
                                                    return item.itemName;
                                                })
                                                : "";
                                            const res = await Addsubject({
                                                dbname: diaParams.current?.dbname,
                                                Data_ID: diaParams.current?.Data_ID,
                                                KMBH: r.KMBHValue !== ""
                                                    ? r.KMBHValue + "~|"
                                                    : r.KMBHAdd + "~|",
                                                KMMC: r.SubjectNumber,
                                                editUser: diaParams.current?.editUser,
                                                PKMBH: "",
                                                YSKMBH: r.KMBHAdd,
                                                YSKMMC: r.SubjectNumber,
                                                KMFX: r.SelectName,
                                                KMLX: r.SelectType,
                                                JC: curNodeRef.current.JC,
                                                itemNames: itemNames ? itemNames.join() : "",
                                            });
                                            if (res.ok) {
                                                notify("增加科目成功", "success", 2000);
                                                getSubjectSDBDatas();
                                            }
                                        }
                                    }
                                    return [];
                                },
                            });
                        }
                        else {
                            if (data.ZWType == 1) {
                                // 判断 是否为 66为辅助类型 99辅助账
                                // if (data.level == 66) {
                                //   console.log(1111);
                                //   // 在辅助类型上 增加 科目参数传递有误
                                //   typeRef.current.show({
                                //     title: "提示",
                                //     okCallback: async () => {
                                //       typeErrorRef.current.show({
                                //         title: "提示",
                                //         okCallback: async () => {
                                //           // 后期在业务组件里面做判断
                                //           const e = curNodeRef.current.KMMC.match(/(\S*)-/);
                                //           SubjectPopupRef.current.show({
                                //             args: {
                                //               title: "新增科目",
                                //               KMBH: curNodeRef.current.KMBH,
                                //               data: res,
                                //               ParentLevel: "",
                                //               ParentLevelKmbh: "",
                                //               PKMBH: data.PKMBH,
                                //             },
                                //             okCallback: async (r: any) => {
                                //               subjectMethod(e, r);
                                //               // const itemNames = r.selectedYears ? r.selectedYears.map((item: any) => {
                                //               //     return item.itemName
                                //               // }) : ''
                                //               // if (e !== null) {
                                //               //     //r ? 有返回参数 说明他有上级科目 : 说明它是增加一级科目
                                //               //     const res = await Addsubject({
                                //               //         dbname,
                                //               //         Data_ID: AccountDataID,
                                //               //         KMBH: r.KMBH !== "" ? r.PKMBH === "" ? r.KMBH + '~|' : r.KMBH : r.KMBHAdd + '~|',
                                //               //         KMMC: r.KMMC !== "" ? r.KMMC + '-' + r.SubjectNumber : r.SubjectNumber,
                                //               //         editUser: username,
                                //               //         PKMBH: r.PKMBH !== "" ? r.PKMBH : "",
                                //               //         YSKMBH: r.KMBHAdd.toString(),
                                //               //         YSKMMC: r.SubjectNumber,
                                //               //         KMFX: r.SelectName,
                                //               //         KMLX: r.SelectType,
                                //               //         JC: r.Satatejc !== "" ? r.Satatejc + 1 : 1,
                                //               //         itemNames: itemNames ? itemNames.join() : '',
                                //               //     })
                                //               //     if (res.ok) {
                                //               //         notify("增加科目成功", 'success', 2000), Refresh(true)
                                //               //     }
                                //               // }
                                //             },
                                //           });
                                //         },
                                //       });
                                //     },
                                //   });
                                // } else if (data.level == 99) {
                                //   const e = curNodeRef.current.KMMC.match(/(\S*)-/);
                                //   // 在辅助账数据上 增加 科目参数传递有误
                                //   SubjectPopupRef.current.show({
                                //     args: {
                                //       title: "新增科目",
                                //       KMBH: curNodeRef.current.KMBH,
                                //       data: res,
                                //       ParentLevel: "",
                                //       ParentLevelKmbh: "",
                                //       PKMBH: data.PKMBH,
                                //     },
                                //     okCallback: async (r: any) => {
                                //       console.log(r, "--rrr-----rrrr");
                                //       subjectMethod(e, r);
                                //       // const itemNames = r.selectedYears ? r.selectedYears.map((item: any) => {
                                //       //     return item.itemName
                                //       // }) : ''
                                //       // if (e !== null) {
                                //       //     //r ? 有返回参数 说明他有上级科目 : 说明它是增加一级科目
                                //       //     const res = await Addsubject({
                                //       //         dbname,
                                //       //         Data_ID: AccountDataID,
                                //       //         KMBH: r.KMBH !== "" ? r.PKMBH === "" ? r.KMBH + '~|' : r.KMBH : r.KMBHAdd + '~|',
                                //       //         KMMC: r.KMMC !== "" ? r.KMMC + '-' + r.SubjectNumber : r.SubjectNumber,
                                //       //         editUser: username,
                                //       //         PKMBH: r.PKMBH !== "" ? r.PKMBH : "",
                                //       //         YSKMBH: r.KMBHAdd.toString(),
                                //       //         YSKMMC: r.SubjectNumber,
                                //       //         KMFX: r.SelectName,
                                //       //         KMLX: r.SelectType,
                                //       //         JC: r.Satatejc !== "" ? r.Satatejc + 1 : 1,
                                //       //         itemNames: itemNames ? itemNames.join() : '',
                                //       //     })
                                //       //     if (res.ok) {
                                //       //         notify("增加科目成功", 'success', 2000), Refresh(true)
                                //       //     }
                                //       // }
                                //     },
                                //   });
                                // }
                            }
                            else {
                                console.log(data, "data----");
                                // 正常增加科目
                                // eslint-disable-next-line @typescript-eslint/no-shadow
                                const e = curNodeRef.current.KMMC.match(/(\S*)-/);
                                const RNewKMBH = await getNewKMBH({
                                    dbname: diaParams.current?.dbname,
                                    Data_ID: diaParams.current?.Data_ID,
                                    KMBH: curNodeRef.current.PID,
                                });
                                SubjectPopupRef.current.show({
                                    args: {
                                        title: "新增科目",
                                        KMBH: curNodeRef.current.KMBH,
                                        data: res,
                                        ParentLevel: ParentLevel.current,
                                        ParentLevelKmbh: RNewKMBH.data[0].YSKMBH,
                                        PKMBH: data.PKMBH,
                                        resolvess: resolvess,
                                    },
                                    okCallback: async (r) => {
                                        console.log(r, "------");
                                        // 修改 变动
                                        const itemNames = r.selectedYears
                                            ? r.selectedYears.map((item) => {
                                                return item.itemName;
                                            })
                                            : "";
                                        if (e !== null) {
                                            // eslint-disable-next-line @typescript-eslint/no-shadow
                                            // 如果 他的上级科目被删除了 执行下方方法
                                            if (r.PKMBHState) {
                                                console.log(r.PKMBHState, "r.PKMBHState---");
                                                const res = await Addsubject({
                                                    dbname: diaParams.current?.dbname,
                                                    Data_ID: diaParams.current?.Data_ID,
                                                    KMBH: r.KMBH !== ""
                                                        ? r.PKMBH === ""
                                                            ? r.KMBH + "~|"
                                                            : r.KMBH
                                                        : r.KMBHAdd + "~|",
                                                    KMMC: r.SubjectNumber,
                                                    editUser: diaParams.current?.editUser,
                                                    PKMBH: "",
                                                    YSKMBH: r.KMBHAdd,
                                                    YSKMMC: r.SubjectNumber,
                                                    KMFX: r.SelectName,
                                                    KMLX: r.SelectType,
                                                    JC: 1,
                                                    itemNames: itemNames ? itemNames.join() : "",
                                                });
                                                if (res.ok) {
                                                    notify("增加科目成功", "success", 2000);
                                                    getSubjectSDBDatas();
                                                }
                                            }
                                            else {
                                                console.log("增加");
                                                const res = await Addsubject({
                                                    dbname: diaParams.current?.dbname,
                                                    Data_ID: diaParams.current?.Data_ID,
                                                    KMBH: r.KMBH !== "" ? r.KMBH : RNewKMBH.data[0].KMBH,
                                                    KMMC: r.KMMC !== ""
                                                        ? r.KMMC + "-" + r.SubjectNumber
                                                        : MatchKMMC[1] + "-" + r.SubjectNumber,
                                                    editUser: diaParams.current?.editUser,
                                                    PKMBH: r.jc ? r.PKMBH : curNodeRef.current.PID,
                                                    YSKMBH: r.KMBHAdd.toString(),
                                                    YSKMMC: r.SubjectNumber,
                                                    KMFX: r.SelectName,
                                                    KMLX: r.SelectType,
                                                    JC: r.Satatejc
                                                        ? r.Satatejc + 1
                                                        : curNodeRef.current.JC,
                                                    itemNames: itemNames ? itemNames.join() : "",
                                                });
                                                if (res.ok) {
                                                    // eslint-disable-next-line @typescript-eslint/no-unused-expressions
                                                    notify("增加科目成功", "success", 2000);
                                                    getSubjectSDBDatas();
                                                }
                                            }
                                        }
                                    },
                                });
                            }
                        }
                    },
                },
                {
                    text: "编辑",
                    onItemClick: async (e) => {
                        const res = await getSubjectType({
                            dbname: diaParams.current?.dbname,
                            Data_ID: diaParams.current?.Data_ID,
                        });
                        const YSKMBH = handleStr(curNodeRef.current.KMBH);
                        console.log(curNodeRef.current, "111111");
                        // 编辑 科目
                        const typeDatas = res.filter((item) => {
                            return item.type.includes(curNodeRef.current.KMLX);
                        });
                        if (curNodeRef.current.isNewAdd) {
                            EditSubjectsReft.current.show({
                                args: {
                                    title: "编辑",
                                    KMMC: curNodeRef.current.KMMC,
                                    KMBH: YSKMBH,
                                    ParentLevel: curNodeRef.current.JC === 1 ? "" : ParentLevel.current,
                                    Typedata: res,
                                    Typename: typeDatas,
                                    subjectFx: curNodeRef.current.KMFX,
                                    itemNames: curNodeRef.current.itemNames,
                                },
                                okCallback: async (v) => {
                                    console.log("确定回调函数");
                                    const itemNames = v.selectedYears
                                        ? v.selectedYears.map((item) => {
                                            return item.itemName;
                                        })
                                        : "";
                                    const r = await Editsubject({
                                        dbname: diaParams.current?.dbname,
                                        Data_ID: diaParams.current?.Data_ID,
                                        KMBH: curNodeRef.current.KMBH,
                                        KMMC: v.SubjectNumber,
                                        editUser: diaParams.current?.editUser,
                                        YSKMMC: v.SubjectNumber,
                                        KMFX: v.SelectName,
                                        KMLX: v.SelectType,
                                        itemNames: itemNames
                                            ? itemNames.join()
                                            : curNodeRef.current.itemNames,
                                    });
                                    if (r.ok) {
                                        notify("编辑科目成功", "success", 2000);
                                        getSubjectSDBDatas();
                                    }
                                },
                            });
                        }
                        else {
                            notify(`科目【${curNodeRef.current.KMMC}】为企业原始辅助账,不可编辑`, "warning", 2000);
                        }
                        // 缺少该字段
                        // if (curNodeRef.current.isNewAdd) {
                        // } else {
                        //   notify(
                        //     `科目【${curNodeRef.current.KMMC}】为企业原始科目,不可编辑`,
                        //     "warning",
                        //     2000
                        //   );
                        // }
                    },
                },
                {
                    text: "删除",
                    onItemClick: (e) => {
                        DeleteSubjectRef.current.show({
                            title: "删除提示",
                            okCallback: async () => {
                                // 删除 科目表
                                const r = await SubjectDel({
                                    dbname: diaParams.current?.dbname,
                                    Data_ID: diaParams.current?.Data_ID,
                                    editUser: diaParams.current?.editUser,
                                    KMBH: curNodeRef.current.KMBH,
                                });
                                if (r.ok) {
                                    notify("删除科目成功", "success", 2000);
                                    getSubjectSDBDatas();
                                }
                                else {
                                    notify(`${r.data}`, "warning", 2000);
                                }
                            },
                        });
                    },
                },
            ];
        }
    };
    const ok = async () => {
        if (diaParams.current?.okCallback) {
            if (diaParamsData.current == undefined) {
                notify("请选择您要选择的科目", "warning", 2000);
            }
            else {
                setVisible(false);
                // 判断 是否为辅助帐
                if (diaParams.current?.auxiliaryState) {
                    // 辅助账
                    const IsHasFZZ = await SubjectIsHasFZZ({
                        dbname: diaParams.current?.dbname,
                        Data_ID: diaParams.current?.Data_ID,
                        KMBH: diaParamsData.current.KMBH,
                    });
                    // 判断 是否存在辅助账
                    if (IsHasFZZ[0].isExists) {
                        // console.log("存在");
                        const IsCanAddFZZState = await IsCanAddFZZ({
                            dbname: diaParams.current?.dbname,
                            Data_ID: diaParams.current?.Data_ID,
                            KMBH: diaParamsData.current.KMBH,
                        });
                        // 存在辅助账 判断是否可以增加辅助账
                        IsCanAddFZZStates(IsCanAddFZZState, diaParamsData.current.KMBH);
                    }
                    else {
                        // console.log("不存在");
                        const IsCanAddFZZState = await IsCanAddFZZ({
                            dbname: diaParams.current?.dbname,
                            Data_ID: diaParams.current?.Data_ID,
                            KMBH: diaParamsData.current.KMBH,
                        });
                        if (IsCanAddFZZState[0].code === 0) {
                            IsMessage(IsCanAddFZZState[0].message);
                            setVisible(false);
                        }
                        else if (IsCanAddFZZState[0].code === 2) {
                            setAddFZZMessage(IsCanAddFZZState[0].message);
                            AuxiliaryRef.current.show({
                                title: "提示",
                                okCallback: async () => {
                                    // const PKMBH = handleStr(value[0].PKMBH);
                                    const value = await AutoAddChildrenForFZZ({
                                        dbname: diaParams.current?.dbname,
                                        Data_ID: diaParams.current?.Data_ID,
                                        KMBH: diaParamsData.current.KMBH,
                                        editUser: diaParams.current?.editUser,
                                    });
                                    const v = await AssistgetType({
                                        dbname: diaParams.current?.dbname,
                                        Data_ID: diaParams.current?.Data_ID,
                                        KMBH: value[0].KMBH,
                                    });
                                    console.log(value, "value------");
                                    diaParams.current?.okCallback(value, v);
                                    setVisible(false);
                                },
                            });
                        }
                    }
                    return [];
                }
                else {
                    // 科目
                    if (diaParamsData.current?.isEnd) {
                        InputRef.current.show({
                            title: "提示",
                            okCallback: () => {
                                setVisible(false);
                                GetautoAddFirstChildren(diaParamsData.current);
                            },
                        });
                    }
                    else {
                        setVisible(false);
                        const r = await getNewKMBH({
                            dbname: diaParams.current?.dbname,
                            Data_ID: diaParams.current?.Data_ID,
                            KMBH: diaParamsData.current.KMBH,
                        });
                        diaParams.current?.okCallback(diaParamsData.current, r.data);
                    }
                }
                setValue("");
                setTbsStates("0");
                TreeListRef.current.instance.searchByText();
                TreeListRef.current.instance.clearSelection();
            }
        }
        return [];
    };
    return (_jsxs("div", { children: [_jsx(DevPopup.Logic, { shadingColor: "rgba(0, 0, 0, 0)", ref: ref, width: 1000, height: 700, visible: visible, title: diaParams.current?.title, onOK: ok, onCancel: () => {
                    setValue("");
                    setVisible(false);
                    setTbsStates("0");
                    TreeListRef.current.instance.searchByText();
                    TreeListRef.current.instance.clearSelection();
                }, onHiding: () => {
                    setValue("");
                    setVisible(false);
                    setTbsStates("0");
                    TreeListRef.current.instance.searchByText();
                    TreeListRef.current.instance.clearSelection();
                }, children: () => {
                    return (_jsxs("div", { style: { width: "100%", height: "100%" }, children: [_jsx("div", { style: { display: "flex" }, children: _jsxs(DevToolBar.Default, { className: "ItemStyle", children: [_jsx(Item, { location: "before", children: _jsx("div", { style: {
                                                    display: "flex",
                                                    alignItems: "center",
                                                    marginLeft: "65px",
                                                }, children: _jsx("span", { style: { color: "red" }, children: "\u63D0\u793A\uFF1A\u53CC\u51FB\u53EF\u9009\u4E2D\u76F8\u5E94\u79D1\u76EE" }) }) }), _jsx(Item, { location: "after", children: _jsxs("div", { style: {
                                                    display: "flex",
                                                    alignItems: "center",
                                                    marginBottom: "10px",
                                                    marginLeft: "20px",
                                                }, children: [_jsx("span", { style: { marginRight: "15px" }, children: _jsx(TextBox, { onInput: (e) => getInputValue(e), width: 200, value: value, className: "TextBoxButtons_Style", buttons: [
                                                                {
                                                                    location: "before",
                                                                    name: "search",
                                                                    options: {
                                                                        icon: "iconfont icon-search",
                                                                        disabled: true,
                                                                    },
                                                                },
                                                            ] }) }), _jsx("span", { className: "refresh_Style", children: _jsx(CpasIcon, { fontSize: 15, type: "icon-refresh", onClick: () => {
                                                                getSubjectSDBDatas();
                                                                getSubjectTypeData();
                                                                setTbsStates("0");
                                                            } }) })] }) })] }) }), _jsxs("div", { style: { display: "flex", height: "98%" }, children: [_jsx("div", { style: { border: "1px solid #ddd", borderRight: "none" }, children: _jsx(HocVerticalLeftStyleTab, { activeKey: TbsStates, className: "SubjectsTabs", tabPosition: "left", tabBarStyle: { background: "#FFF" }, onChange: AccountTabsClick, children: Array.isArray(tabsData)
                                                ? tabsData.map((item) => {
                                                    return (_jsx(AntTabs.Panel, { tab: item.type, style: { marginTop: "5px" } }, item.code));
                                                })
                                                : "" }) }), _jsxs(TreeList, { selection: {
                                            recursive: true,
                                            mode: selectMode === "0" ? "single" : "multiple",
                                        }, className: "PublicTreeList", ref: TreeListRef, dataSource: SubjectSDBDatas, allowColumnResizing: true, columnAutoWidth: true, showRowLines: true, showBorders: true, columnResizingMode: "widget", columnMinWidth: 100, parentIdExpr: "PID", keyExpr: "ID", id: "Code", width: "95%", height: "100%", onCellClick: onCellClick, onCellDblClick: onCellDblClick, 
                                        // 显示斑马线
                                        rowAlternationEnabled: true, children: [_jsx(Column, { dataField: "code", caption: "\u79D1\u76EE\u7F16\u53F7", width: 130, alignment: "left" }), _jsx(Column, { dataField: "KMMC", caption: "\u79D1\u76EE\u540D\u79F0", width: 200, alignment: "left" }), _jsx(Column, { dataField: "KMFX", caption: "\u79D1\u76EE\u65B9\u5411", width: 80, alignment: "center" }), _jsx(Column, { dataField: "QCYE", caption: "\u671F\u521D\u4F59\u989D", width: 120, alignment: "right", cellRender: (cell) => {
                                                    return cell.data.QCYE !== 0
                                                        ? cell.data.QCYE !== null
                                                            ? moneyFormat(cell.data.QCYE)
                                                            : ""
                                                        : "";
                                                } }), _jsx(Column, { dataField: "JFLJFSE", caption: "\u501F\u65B9\u7D2F\u8BA1", width: 130, alignment: "right", cellRender: (cell) => {
                                                    return cell.data.JFLJFSE !== 0
                                                        ? cell.data.JFLJFSE !== null
                                                            ? moneyFormat(cell.data.JFLJFSE)
                                                            : ""
                                                        : "";
                                                } }), _jsx(Column, { dataField: "DFLJFSE", caption: "\u8D37\u65B9\u7D2F\u8BA1", width: 130, alignment: "right", cellRender: (cell) => {
                                                    return cell.data.DFLJFSE !== 0
                                                        ? cell.data.DFLJFSE !== null
                                                            ? moneyFormat(cell.data.DFLJFSE)
                                                            : ""
                                                        : "";
                                                } }), _jsx(Column, { dataField: "QMYE", caption: "\u671F\u672B\u4F59\u989D", width: 130, alignment: "right", cellRender: (cell) => {
                                                    return cell.data.QMYE !== 0
                                                        ? cell.data.QMYE !== null
                                                            ? moneyFormat(cell.data.QMYE)
                                                            : ""
                                                        : "";
                                                } }), _jsx(Column, { dataField: "itemNames2", caption: "\u62A5\u8868\u9879\u76EE", width: 130, alignment: "left" })] })] })] }));
                } }), _jsx(DevPopup.Default, { ref: InputRef, children: () => {
                    //
                    return (_jsx("span", { children: `科目【${diaParamsData.current?.KMMC}】为末级科目，是否继续为其增加下级科目` }));
                } }), _jsx(DevPopup.Default, { ref: AuxiliaryRef, children: () => {
                    //
                    return _jsx("span", { children: AddFZZMessage });
                } }), _jsx(DevPopup.Default, { ref: AuxiliaryRefs, children: () => {
                    //
                    return (_jsx("span", { children: `科目【${diaParamsData.current?.KMMC}】为非末级，无法增加辅助帐` }));
                } })] }));
});
export default React.memo(AddPopup);
